package messages;

import java.util.ArrayList;

import DBComm.Buddy;

public class ReturnBuddyListMessage extends Message
{
	private String username;
	private ArrayList<Buddy> buddies = new ArrayList<Buddy>();
	
	public ReturnBuddyListMessage() {super("ReturnBuddyList");}
	public ReturnBuddyListMessage(String username)
	{
		super("ReturnBuddyList");
		this.username = username;
	}
	
	public void setUsername(String username) {this.username = username;}
	
	public String getUsername() {return username;}
	
	public void printMessage()
	{
		System.out.println("Message (username: " + username + ") (BuddyList requested)");
//		System.out.println("Sent at: " + timestamp);
//		System.out.println("Text: " + text);
//		System.out.println("User: " + username + " updated his/her status : " + from + " Added Buddy - " + to);
		System.out.println();
	}
	
	public void addBuddy(Buddy b) {buddies.add(b);}
	public void setBuddyList(ArrayList<Buddy> buddyList) {this.buddies = buddyList;}
	
	// return an XML-formatted version of the message
	public String toXML()
	{
		String message = "<message>";
        message += "<type>ReturnBuddyList</type>";
        message += "<username>" + username + "</username>";
        message += "<buddies>";
        
        for(Buddy b : buddies)
        {
        	message += "<buddy>";
        	message += "<username>" + b.getBuddy() + "</username>";
        	message += "<status>" + b.getStatus() + "</status>";
        	message += "</buddy>";
        }
        
        message += "</buddies>";
        message += "</message>\n\0";
        
        return message;
	}
}

